﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta charset="utf-8" />
    <link href="../../Scripts/easyUI145/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/bootstrap/css/css.css" type="text/css" rel="stylesheet" media="all" />
    <link href="../../Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />
    <!-- 该文件可以被集成厂商自己定义风格,可以自己修改,以达到流程设计器与自己的系统风格统一. -->
    <script src="../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Scripts/CommonUnite.js" type="text/javascript"></script>
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
</head>

    <script type="text/javascript">
        var myPK = GetQueryString("MyPK");
        var func = new Entity("BP.CCBill.Template.MethodFunc", myPK);
        //js时先加载js文件
        if (func.MethodDocTypeOfFunc == 1) {
            //加载执行方法的js
            loadJs('../../../DataUser/JSLibData/Method/' + myPK + '.js', function () { doMethod(); });
        } else doMethod();

        function loadJs(url, callback) {
            var script = document.createElement('script');
            script.type = "text/javascript";
            if (typeof (callback) != "undefined") {
                if (script.readyState) {
                    script.onreadystatechange = function () {
                        if (script.readyState == "loaded" || script.readyState == "complete") {
                            script.onreadystatechange = null;
                            callback();
                        }
                    }
                } else {
                    script.onload = function () {
                        callback();
                    }
                }
            }
            script.src = url;
            document.getElementsByTagName("head")[0].appendChild(script);
            //sdocument.body.appendChild(script);
        }
        function doMethod() {
            $("#Msg").html("正在执行方法，请稍后......");

            var frmID = GetQueryString("FrmID");
            var workID = GetQueryString("WorkID");
            

            //要执行sql.
            if (func.MethodDocTypeOfFunc == 0) {
                var handler = new HttpHandler("BP.CCBill.WF_CCBill");
                handler.AddUrlData();
                var data = handler.DoMethodReturnString("DoMethod_ExeSQL"); //执行SQLs
                alert(data);
                $("#Msg").html(data);


                // $('#bootStrapdlg').modal('hide');
                // $('#bootStrapdlg', parent.document).remove();
                return data;
            }


            //要执行script.  wangyanyan完成.
            if (func.MethodDocTypeOfFunc == 1) {
                var script = func.DoMethodReturnString("Gener_MethodDoc_JavaScript");

                //获得单据的数据.
                // var geEn = new Entity(func.FrmID, workID);
                //替换script的变量.
                //   alert(script);
                //                //Opera、FF、Chrome等：
                //                var script = document.createElement("script");
                //                script.setAttribute("type", "text/javascript");
                //                script.onload = function () {
                //                    alert("加载成功啦！");
                //                }
                //                script.setAttribute("src", scripts[i]);
                // script = " var en =new Entity('Dict_XueShengJiBenXinXi',workID);  ";
                //script += " alert(en.OID); en.Email='zzzz';en.Update();  ";




                //执行这个script.
                try {
                    var data = eval(func.MethodID+"()");
               
                    return data;
                } catch (e) {
                    $("#Msg").html(e);
                    // $('#bootStrapdlg').modal('hide');
                    //$/('#bootStrapdlg', parent.document).remove();
                    return;
                }

                //提示信息.
                return;
            }

            //要执行url.  wangyanyan完成.
            if (func.MethodDocTypeOfFunc == 2) {

                var url = func.MethodDoc;
                if (url.indexOf('?') == -1)
                    url += "?FrmID=" + GetQueryString("FrmID") + "&WorkID=" + GetQueryString("WorkID");
                else
                    url += "&FrmID=" + GetQueryString("FrmID") + "&WorkID=" + GetQueryString("WorkID");

                //增加上表单的参数.
                for (var i = 0; i < attrs.length; i++) {
                    var attr = attrs[i];

                    if (attr.UIContralType == 0) {
                        url += "&" + attr.KeyOfEn + "=" + $("#TB_" + attr.KeyOfEn).val();
                        continue;
                    }

                    if (attr.UIContralType == 1) {
                        url += "&" + attr.KeyOfEn + "=" + $("#DDL_" + attr.KeyOfEn).val();
                        continue;
                    }

                    if (attr.UIContralType == 2) {
                        url += "&" + attr.KeyOfEn + "=" + $("#CB_" + attr.KeyOfEn).val();
                        continue;
                    }
                    if (attr.UIContralType == 3) {
                        url += "&" + attr.KeyOfEn + "=" + $("#RB_" + attr.KeyOfEn).val();
                        continue;
                    }
                }

                //执行url返回数据.
                var data = DBAccess.RunUrlReturnString(url);

                if (func.MsgSuccess == "")
                    func.MsgSuccess = "执行成功.";

                if (func.MsgErr == "")
                    func.MsgErr = "执行失败.";

                if (data.indexOf('err@') == -1) {

                    $("#Msg").html(func.MsgErr + "#" + data);
                    //$('#bootStrapdlg', parent.document).modal('hide');
                    //$('#bootStrapdlg', parent.document).remove();
                    return;
                }
                $("#Msg").html(data);
                //alert(data);
            }

        }

        function DoScript(func) {

        }
    </script>
    <body>
        <div id="Msg"></div>
    </body>
</html>
